package observerapplication;

import java.util.ArrayList;
import java.util.List;


// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.EDB88DFB-B7A3-1463-B22F-4947D5FE7237]
// </editor-fold> 
public class Magatzem2 implements Subject {

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.B0933FFB-16DE-2322-9F8F-5EECD78334E0]
    // </editor-fold> 
    private List<Observer> observadors;

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.057F364C-BF8E-6A37-3F48-A0CEAD16FD80]
    // </editor-fold> 
    private int stock;

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.BB29D9A4-A31B-3D43-8439-60686CA85040]
    // </editor-fold> 
    public Magatzem2 () {
        observadors = new ArrayList<Observer>();
        stock = 5;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.622F6227-F4F8-9071-5028-04C449CEDCDA]
    // </editor-fold> 
    public void add (Observer observer) {
        observadors.add(observer);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.0158B791-6FE7-365E-548C-25103CC2E23F]
    // </editor-fold> 
    public void remove (Observer observer) {
        observadors.remove(observer);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.00F2E766-DAEC-4532-FD52-CDE1C8106C87]
    // </editor-fold> 
    public void decrementaStock () {
        this.stock--;
        if (this.stock==3){
             for (Observer observer: observadors){
                observer.update();
            }
        }
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.21BF5C50-5B53-B2B6-C6C3-3151D66BBB8E]
    // </editor-fold> 
    public List<Observer> getObservadors () {
        return observadors;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.8FB90CC4-C4F8-0CD6-770C-2DC22EEDE482]
    // </editor-fold> 
    public void setObservadors (List<Observer> val) {
        this.observadors = val;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.4C58E5A8-37FB-367C-2746-94EA380DE183]
    // </editor-fold> 
    public int getStock () {
        return stock;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,regenBody=yes,id=DCE.0CD8747E-CEA5-58C8-6CDA-7ADCA9375D10]
    // </editor-fold> 
    public void setStock (int val) {
        this.stock = val;
    }

}

